var openId = '';
$(document).ready(function () {
    setWXConfig(preUrl + "PaymentQuery.html");

    document.getElementById("bottom").style.marginTop = ((document.body.scrollHeight - document.body.clientHeight)-30) + "px";
    document.getElementById("bottom").style.display = "block";
    getOpenId();
    jQuery.support.cors = true;
    $.ajaxSettings.async = true;
    $.ajax({
        type: "GET",
        url: preUrl + "account/" + openId,
        async: false,
        success: function (data) {
            if (typeof(data) == "undefined") {
                alert("访问服务器失败，请稍后重试");
            } else {
                if (data.resCode == "0000") {
                    var resList = data.resList;
                    if (resList == null || resList.length == 0) {
                        document.getElementById("hisAccount").style.display = "none";
                    } else {
                        var accountNo = document.getElementById("accountNo");
                        var content = "<div style='position:absolute;width:100%;height:100%;border:1px solid #ccc;background:#efefef; display:block;'><div style='background:#ddd; display:block; height:33px; cursor:move;'><i style=' float:right; line-height:33px; padding:0 8px; color:#777; cursor:default;' onclick='layer.closeAll();'>关闭</i></div>";
                        $.each(resList, function (i, account) {
                           content += "<div style='font-size: 18px;' onclick=\"$(\'#accountNo\').val('" +account.accountNo+"\');layer.closeAll();\"\>" + account.accountNo + "</div>  "
                        });
                        content += "</div>";
                        $("#hisAccount").click(function(){
                            layer.open({
                                type: 1,
                                content: content,
                                shadeClose:false,
                                style: 'position:center; left:0; top:0; width:80%; height:80%; border:none;border:none;'
                            });
                        });
                    }
                } else {
                    alert("访问服务器失败，请稍后重试");
                }
            }
        }
    });
});
function query() {
    var paras = getUrlParameters();
    var accountNo = $('#accountNo').val().trim();
    if (accountNo == null || accountNo == '') {
        alert('缴费户号不能为空');
        return;
    }
    var re = /^[0-9]+[0-9]*]*$/;

    if (!re.test(accountNo)) {
        alert("缴费户号必须为纯数字");
        $('#accountNo').val('');
        return;
    }

    // if(account.length < 8) {
    // 	alert("缴费卡号长度必须为8位");
    // 	return;
    //}

    document.getElementById('loadDiv').style.display = 'block';
    var accountType = $('#accountType').val();
    var predata = {"accountNo": accountNo};
    $.ajax({
        url: preUrl + "account/" + getOpenIdByCookie() + "/" + accountType,
        type: "post",
        dataType: "json",
        data: predata,
        success: function (data) {
            if (typeof(data) == "undefined") {
                alert("访问服务器失败，请稍后重试");
            } else {
                if (data.resCode == "0000") {
                    window.location.href = 'Payment.html?id=' + data.id + '&accountNo=' + accountNo;
                } else if (data.resCode == '2000') {
                    $("#allDiv").html('');
                    document.getElementById('allDiv').style.display = 'block';
                    var content = '<div style="background:#f7f7f7"><div '
                        + 'style="padding-top:50px;text-align:center;font-size:14px;color:#808080;'
                        + 'padding-bottom:30px;" >' + data.errorinfo
                        + '</div></div>';
                    $("#allDiv").append(content);
                } else {
                    alert("访问服务器失败，请稍后重试");
                }
            }
        },
        error: function (data) {
            alert("访问服务器失败，请稍后重试");
        }
    });

}
